﻿using XNAFight.Scene.Core;
using Microsoft.Xna.Framework;
using System;
using XNAFight.Engine.Inputs;
using XNAFight.Characters.Core;
using XNAFight.Players;
using XNAFight.Scene.CharacterSelection;

namespace XNAFight.Scene.SandBoxOne
{
    class SandBoxOneCharacterSelect : CharacterSelect
    {
        public SandBoxOneCharacterSelect()
            : base(1, 0, 2)
        {
            this.Completed += launchGame;
        }

        public override void Draw(GameTime _gameTime)
        {
            GraphicsDevice.Clear(Color.White);

            CommonContent.SpriteBatch.Begin();

            int nb_characters_selected = character_picker.getPlayersNbCharacters(1);

            #region TEAM 1

            WriteLine("Player 1", CommonContent.SmallFont);
            if (!control_pickers[0].IsControlerOk)
                WriteLine("Press start", CommonContent.SmallFont);
            else
            {
                WriteLine(control_pickers[0].Controler.ToString(), CommonContent.SmallFont);
                if (nb_characters_selected > 0)
                    WriteLine(character_picker.persos_team_1[0][0], CommonContent.SmallFont);
                else
                    WriteLine("Choose your character", CommonContent.SmallFont);
            }
            #endregion

            #region TEAM 2

            WriteLine("Punching bag", CommonContent.SmallFont, true);

            if (nb_characters_selected == 2)
                WriteLine(character_picker.persos_team_1[0][1], CommonContent.SmallFont, true);
            else if (nb_characters_selected == 1)
                WriteLine("Choose the punching bag character", CommonContent.SmallFont, true);

            #endregion

            CommonContent.SpriteBatch.End();
        }

        private void launchGame()
        {
            Controler controler = getTeam1Controlers()[0];

            // To do : La configuration des touches devra etre recupérée ailleurs
            InGameInputConfiguration input_conf;

            if (controler.Type == InputType.Keyboard)
                input_conf = new InGameKeyboardConfiguration();
            else
                input_conf = new InGamePadConfiguration(controler.Index);
            
            Program.LaunchSandBoxOne(getTeam1Characters()[0][0], getTeam1Characters()[0][1], controler, input_conf);
        }

        protected void launchGame(object _sender, EventArgs _e)
        {
            launchGame();
        }
        
    }
}
